package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SearchRoot;

import java.util.List;

/**
 * Created by dllo on 15/10/23.
 */
public class SearchEnterAadpter extends BaseAdapter {
    private List<SearchRoot.DataEntity> dataEntities;
    private Context mcontext;
    private SearchRoot.DataEntity entity;


    public SearchEnterAadpter(Context context, List<SearchRoot.DataEntity> data) {
        mcontext = context;
        dataEntities = data;
    }


    @Override
    public int getCount() {
        return dataEntities != null && dataEntities.size() > 0 ? dataEntities.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return dataEntities != null && dataEntities.size() > 0 ? dataEntities.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.search_item, null);
            holder = new ViewHolder();
            holder.search_item = (TextView) convertView.findViewById(R.id.search_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        entity = (SearchRoot.DataEntity) getItem(position);
        if (entity != null) {
            holder.search_item.setText(entity.getVal());
        }

        return convertView;
    }

    private class ViewHolder {
        private TextView search_item;
    }
}
